if not tools then
  tools = {}
end
if tools.Event then
  tools.Event:clearAllListener()
end
local Event = object:new()
tools.Event = Event
local handlers_ = {}
function Event:attach(name, listener, autoObserver)
  if not self:judgeRegisted(name, autoObserver) then
    local hds = {}
    hds.handler = listener
    hds.removed = false
    hds.name = name
    hds.autoObserver = autoObserver
    table.insert(handlers_, hds)
  else
    for k, hds in pairs(handlers_) do
      if hds.name == name and hds.autoObserver and autoObserver and hds.autoObserver == autoObserver then
        hds.handler = listener
        break
      end
    end
    print("==\228\186\139\228\187\182\229\144\141===" .. name .. "=\239\188\157\239\188\157\239\188\157=\228\190\166\229\144\172\232\128\133=\239\188\157\239\188\157\239\188\157\239\188\157=" .. autoObserver .. "\229\183\178\231\187\143\232\162\171\228\187\163\230\155\191\228\186\134\239\188\140\232\175\183\231\161\174\229\174\154\230\152\175\229\144\166\232\166\129\230\179\168\229\134\140")
  end
end
function Event:judgeRegisted(name, autoObserver)
  if not name or not autoObserver then
    print("======\231\169\186\231\154\132\228\186\139\228\187\182\229\144\141\229\173\151  \231\169\186\231\154\132\228\190\166\229\144\172\232\128\133\229\144\141\229\173\151============")
    return false
  end
  for k, hds in pairs(handlers_) do
    if hds.name == name and hds.autoObserver and autoObserver and hds.autoObserver == autoObserver then
      return true
    end
  end
  return false
end
function Event:printAllEvent()
  for k, hds in pairs(handlers_) do
    print("===hds.name===" .. hds.name .. "===hds.autoObserver===" .. hds.autoObserver)
  end
end
function Event:trigger(name, ...)
  if not name then
    print("======\231\169\186\231\154\132\228\186\139\228\187\182\229\144\141\229\173\151 \230\151\160\230\179\149\230\138\155\229\135\186\228\186\139\228\187\182============")
    return
  end
  for k, hds in pairs(handlers_) do
    if hds.name == name then
      hds.handler(...)
    end
  end
end
function Event:removeByHandler(handle)
  if not handle then
    print("======\231\169\186\231\154\132\229\155\158\232\176\131\230\150\185\230\179\149 \230\151\160\230\179\149\231\167\187\233\153\164\228\186\139\228\187\182============")
    return
  end
  for i = #handlers_, 1, -1 do
    local hds = handlers_[i]
    if not hds.handler == handle then
      table.remove(handlers_, i)
    end
  end
end
function Event:removeByName(name)
  if not name then
    print("======\231\169\186\231\154\132\228\186\139\228\187\182\229\144\141  \230\151\160\230\179\149\231\167\187\233\153\164\228\186\139\228\187\182============")
    return
  end
  for i = #handlers_, 1, -1 do
    local hds = handlers_[i]
    if hds.name == name then
      table.remove(handlers_, i)
    end
  end
end
function Event:removeByObserverName(name)
  if not name then
    print("======  \231\169\186\231\154\132\228\190\166\229\144\172\232\128\133\229\144\141\229\173\151\239\188\140 \230\151\160\230\179\149\231\167\187\233\153\164\228\186\139\228\187\182============")
    return
  end
  for i = #handlers_, 1, -1 do
    local hds = handlers_[i]
    if hds.autoObserver and hds.autoObserver == name then
      table.remove(handlers_, i)
    end
  end
end
function Event:removeByEventNameAndObserverName(ename, oname)
  if not ename or not oname then
    print("======\231\169\186\231\154\132\228\186\139\228\187\182\229\144\141 \230\136\150\231\169\186\231\154\132\228\190\166\229\144\172\232\128\133\229\144\141\229\173\151\239\188\140 \230\151\160\230\179\149\231\167\187\233\153\164\228\186\139\228\187\182============")
    return
  end
  for i = #handlers_, 1, -1 do
    local hds = handlers_[i]
    if hds.name == ename and hds.autoObserver and oname and hds.autoObserver == oname then
      table.remove(handlers_, i)
    end
  end
end
function Event:clearAllListener()
  for i = #handlers_, 1, -1 do
    local hds = handlers_[i]
    table.remove(handlers_, i)
  end
  handlers_ = {}
end
